import os
import shutil

# 获取当前文件的绝对路径
current_file_path = os.path.abspath(__file__)
# 获取当前文件所在的文件夹路径
current_dir = os.path.dirname(current_file_path)

print(f"当前文件的路径: {current_file_path}")
print(f"当前文件所在的文件夹: {current_dir}")



def searchAndCopyFile(source_dir, target_dir):
    # 如果目标文件夹不存在，则创建
    if not os.path.exists(target_dir):
        os.makedirs(target_dir)

    # 遍历源文件夹
    for root, dirs, files in os.walk(source_dir):
        for file in files:
            # 检查文件扩展名
            if file.endswith('.h') or file.endswith('.hpp'):
                # 获取文件的完整路径
                source_file = os.path.join(root, file)
                # 复制文件到目标文件夹
                shutil.copy(source_file, target_dir)
                print(f'已复制: {source_file} 到 {target_dir}')


if __name__ == '__main__':
    # 配置需要遍历的文件夹
    folders = [
        os.path.join(current_dir, "src"),
        os.path.join(current_dir, "third"),
    ]
    for folder in folders:
        searchAndCopyFile(folder,os.path.join(current_dir, "include"))
